package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.BusinessStatusConstants;
import com.qk.domain.business.BusinessDO;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessListDTO;
import com.qk.dto.business.BusinessFollowDTO;
import com.qk.dto.business.PoolDTO;
import com.qk.entity.Business;
import com.qk.management.service.BusinessService;
import com.qk.vo.business.QueryBusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @GetMapping("/pool")
    public Result pool(PoolDTO dto){
        PageResult<Business> businessPageResult=businessService.pool(dto);
        return Result.success(businessPageResult);
    }
    @PutMapping
    public Result followBusiness(@RequestBody BusinessFollowDTO dto) {
        businessService.followBusiness(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id) {
        QueryBusinessVO queryBusinessVO = businessService.queryById(id);
        return Result.success();
    }
    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id){
        businessService.businessToCustomer(id);
        return Result.success();
    }
    @PutMapping("/back/{id}")
    public Result back(@PathVariable Integer id){
        businessService.backBusiness(id);
        return Result.success();
    }
    @PutMapping("/assign/{businessId}/{userId}")
    public Result assign(@PathVariable Integer businessId, @PathVariable Integer userId){
        businessService.updateById(Business.builder()
                .id(businessId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(BusinessStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }
    @PostMapping
    public Result addRlue(@RequestBody BusinessDTO dto) {
        businessService.addBusiness(dto);
        return Result.success();
    }
    @GetMapping
    public Result list(BusinessListDTO dto){
       PageResult<BusinessDO> result = businessService.businessList(dto);
       return Result.success(result);
    }

}
